package com.group01.community.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.group01.community.entity.SysOperLog;
import com.group01.community.service.SysOperLogService;
import com.group01.community.utils.ExcelUtils;
import com.group01.community.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * <p>
 * 操作日志记录 前端控制器
 * </p>
 *
 * @author iuoly
 * @since 2022-07-04
 */
@Api
@RestController
@RequestMapping("/sysOperLog")
public class SysOperLogController {
    @Autowired
    private SysOperLogService sysOperLogService;

    @ApiOperation("添加")
    @PostMapping
    public ResponseResult<String> add(@RequestBody SysOperLog sysOperLog) {
        return null;
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/{operIds}")
    public ResponseResult<String> delete(@PathVariable Long[] operIds) {
        sysOperLogService.removeByIds(Arrays.asList(operIds));
        return ResponseResult.ok("删除成功");
    }

    @ApiOperation("清空")
    @DeleteMapping("/clear")
    public ResponseResult<String> clear() {
        sysOperLogService.remove(null);
        return ResponseResult.ok("清空成功");
    }

    @ApiOperation("带条件查询")
    @PostMapping("/condition")
    public ResponseResult<IPage<SysOperLog>> selectCondition(@RequestBody SysOperLog sysOperLog, Long current, Long size) {
        return ResponseResult.ok(sysOperLogService.selectCondition(sysOperLog, current, size));
    }

    @ApiOperation("导出")
    @GetMapping("/export")
    public ResponseResult<String> export(HttpServletResponse resp) {
        ExcelUtils.export(SysOperLog.class, sysOperLogService, resp, "操作日志信息");
        return ResponseResult.ok("ok");
    }
}

